﻿using System;
using System.Windows.Forms;

namespace Useful
{
    public static class MessageBoxHelper
    {
        public static void ShowWarring(string text)
        {
            ShowWarring(text, "Внимание");
        }

        public static void ShowWarring(Form owner, string text)
        {
            MessageBox.Show(owner, text, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        public static void ShowWarring(string text, string caption)
        {
            MessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        public static void ShowError(string text)
        {
            ShowError(text, "Ошибка");
        }

        public static void ShowError(Exception ex)
        {
            string str;

            if (!String.IsNullOrEmpty(ex.Message))
                str = ex.Message;
            else if (ex.InnerException != null && !String.IsNullOrEmpty(ex.InnerException.Message))
                str = ex.InnerException.Message;
            else
                str = ex.ToString();

            ShowError(str);
        }

        public static void ShowError(string text, string caption)
        {
            MessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public static bool ShowQuestion(string text)
        {
            return ShowQuestion(text, "Внимание", MessageBoxButtons.YesNo) == DialogResult.Yes;
        }

        public static bool ShowQuestion(Form owner, string text)
        {
            return MessageBox.Show(owner, text, "Внимание", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;
        }

        public static DialogResult ShowQuestion(string text, MessageBoxButtons buttons)
        {
            return ShowQuestion(text, "Внимание", buttons);
        }

        public static DialogResult ShowQuestion(string text, string caption)
        {
            return ShowQuestion(text, caption, MessageBoxButtons.YesNo);
        }

        public static DialogResult ShowQuestion(string text, string caption, MessageBoxButtons buttons)
        {
            return ShowQuestion(text, caption, buttons, MessageBoxDefaultButton.Button2);
        }

        public static DialogResult ShowQuestion(string text, string caption, MessageBoxButtons buttons, MessageBoxDefaultButton defButton)
        {
            return MessageBox.Show(text, caption, buttons, MessageBoxIcon.Question, defButton);
        }

        public static DialogResult ShowQuestion(string text, string caption, MessageBoxButtons buttons, MessageBoxDefaultButton defButton, MessageBoxIcon icon)
        {
            return MessageBox.Show(text, caption, buttons, icon, defButton);
        }

        public static void ShowInformation(string text)
        {
            ShowInformation(text, "Внимание");
        }

        public static void ShowInformation(string text, string caption)
        {
            MessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public static void Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
        {
            MessageBox.Show(text, caption, buttons, icon);
        }

        public static void ShowAsterisk(string text)
        {
            MessageBox.Show(text, "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }

        public static void ShowExclamation(string text)
        {
            MessageBox.Show(text, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }

        public static void ShowExclamation(Form owner, string text)
        {
            MessageBox.Show(owner, text, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
    }
}
